package com.emm.yixun.mobile.adapter;

import java.util.ArrayList;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;

import com.emm.yixun.mobile.R;
import com.emm.yixun.mobile.model.GetMarketingControlList.UnitList.FloorList;
import com.emm.yixun.mobile.ui.housing.MarketingControlActivity;
import com.eroad.product.tools.MyGridView;

/**
 * 
 * 
 * <p>
 * <b>Title：</b>横向列表适配器
 * </p>
 * <p>
 * <b>Description：</b>房源模块下
 * </p>
 * 
 * @author tangxin
 * @date 2016年12月13日 下午2:36:55
 */
public class Hzor_adapter extends BaseAdapter {

	Activity context;
	ArrayList<FloorList> list;

	/**当前一排最大长度*/
	int MAXCOUNT = 0;

	public Hzor_adapter(Activity context, ArrayList<FloorList> list) {
		this.context = context;
		this.list = list;
		GetMAXCOUNT(this.list);
	}

	/**
	 * <p>
	 * <b>Title：</b> 获取list内子list的最大长度值
	 * </p>
	 * <p>
	 * <b>Description：</b>
	 * </p>
	 * 
	 * @param list 
	 * 
	 * @author tangxin
	 * @date 2016年12月13日 下午2:37:32
	 */
	private void GetMAXCOUNT(ArrayList<FloorList> list) {

		if (null == list) {// list为空的时候，不获取最大值
			return;
		} else {
			for (int i = 0; i < list.size(); i++) {
				if (MAXCOUNT <= list.get(i).getRoomList().size()) {
					MAXCOUNT = list.get(i).getRoomList().size();
				}
			}
		}
	}

	@Override
	public int getCount() {
		return list == null ? 0 : list.size();
	}

	@Override
	public Object getItem(int position) {
		return list == null ? null : list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHoudlert v = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.horizontal_marketing_item, null);
			v = new ViewHoudlert();
			v.grid = (MyGridView) convertView.findViewById(R.id.grid);
			v.bg_linear = (LinearLayout) convertView.findViewById(R.id.bg_linear);
			convertView.setTag(v);
		} else {
			v = (ViewHoudlert) convertView.getTag();
		}

		MarketingControlActivity.setGridView(context, v.grid, 100, MAXCOUNT);

		Marketing_Grid_Adapter adapter = new Marketing_Grid_Adapter(context, list.get(position).getRoomList());
		v.grid.setAdapter(adapter);

		return convertView;
	}

	public static class ViewHoudlert {
		MyGridView grid;

		LinearLayout bg_linear;
	}

}
